 <?php
  use yii\helpers\Html;
  use yii\helpers\Url;
  use yii\bootstrap\ActiveForm;
  use yii\widgets\LinkPager;

  $this->title = 'datalist';
 ?>

<div class="box">
  <div class="box-header">
    <h3 class="box-title">流程列表</h3>
  </div>
  <!-- /.box-header -->
  <div class="box-body">
    <table id="example1" class="table table-bordered table-striped">
      <thead>
      <tr>
        <th>所属流程</th>
        <th>转接部门</th>
        <th>承接部门</th>
        <th>排序</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <?php foreach ($model as $val) :?>
      <tr>
        <td><?= $val->name?></td>
        <td><?= $depart_arr[$val->tran_depart] ?></td>
        <td><?= $depart_arr[$val->undertake_depart] ?></td>
        <td><input type="text" class="order" value="<?= $val->order?>" pid="<?= $val->id?>"></td>
        <td><a href="<?= Url::toRoute(['process/create', 'id' => $val->id])?>"><button class="btn btn-info">修改流程</button></a></td>
      </tr>
      <?php endforeach;?>
      </tbody>
    </table>
  </div>
</div>

<script type="text/javascript" src="js/jquery.js"></script> 
<script>
  $(".order").change(function(){
    var val = $(this).val();
    var id = $(this).attr('pid');
    var url = "<?= Url::toRoute('process/order')?>";
    var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
    $.ajax({
      type:"GET",
      url:url,
      data:{
        _csrf:_csrf,
        id:id,
        val:val
      },
      dataType:"json",
      success:function(json){
        if (json.flag == true) {
          window.location.href = "http://localhost/advanced/backend/web/index.php?r=process/datalist";
        } else {
          alert('排序失败');
        }
      },
      error:function(){
        alert('网络忙');
      }
    });
  });
</script>
